function o(o) {
    var e, r, n, t, a;
    switch ((e = o.getFromAccount()) || (e = ""), (r = o.getFromAccountNick()) || (r = e), 
    n = o.getSession().type(), t = o.getSubType(), n) {
      case h.SESSION_TYPE.C2C:
        switch (t) {
          case h.C2C_MSG_SUB_TYPE.COMMON:
            a = i(o), h.Log.warn("receive a new c2c msg: fromAccountNick=" + r + ", content=" + a);
            var c = {
                To_Account: e,
                LastedMsgTime: o.getTime()
            };
            h.c2CMsgReaded(c), console.error("收到一条c2c消息(好友消息或者全员推送消息): 发送人=" + r + ", 内容=" + a);
        }
        break;

      case h.SESSION_TYPE.GROUP:
    }
}

function e(o, e, t, i) {
    h.login(o, e, t, function(e) {
        console.debug(e), console.debug(e), h.Log.info("webim登录成功"), O = o, r({
            ProfileItem: [ {
                Tag: "Tag_Profile_IM_Nick",
                Value: o.identifierNick
            } ]
        }, function() {
            n(i);
        }), l(O.identifierNick + "进入房间", function() {});
    }, function(o) {
        console.error(o.ErrorInfo);
    });
}

function r(o, e) {
    h.setProfilePortrait(o, function(o) {
        h.Log.info("修改昵称成功"), e && e();
    }, function() {});
}

function n(o) {
    var e = {
        GroupId: o
    };
    h.applyJoinBigGroup(e, function(e) {
        e.JoinedStatus && "JoinedSuccess" == e.JoinedStatus ? (h.Log.info("进群成功"), R = o) : console.error("进群失败");
    }, function(o) {
        console.error(o.ErrorInfo);
    });
}

function t(o) {
    var e, r;
    o.getFromAccount(), (e = o.getFromAccountNick()) || (e = "未知用户"), o.getSession().type(), 
    r = o.getSubType(), o.getIsSend();
    var n = "";
    switch (r) {
      case h.GROUP_MSG_SUB_TYPE.COMMON:
        n = i(o);
        break;

      case h.GROUP_MSG_SUB_TYPE.REDPACKET:
        n = "[群红包消息]" + i(o);
        break;

      case h.GROUP_MSG_SUB_TYPE.LOVEMSG:
        n = "[群点赞消息]" + i(o), G();
        break;

      case h.GROUP_MSG_SUB_TYPE.TIP:
        n = "[群提示消息]" + i(o);
    }
    return {
        fromAccountNick: e,
        content: n
    };
}

function i(o) {
    var e, r, n, t, i = "";
    e = o.getElems();
    for (var p in e) switch (r = e[p], n = r.getType(), t = r.getContent(), n) {
      case h.MSG_ELEMENT_TYPE.TEXT:
        i += a(t);
        break;

      case h.MSG_ELEMENT_TYPE.FACE:
        i += c(t);
        break;

      case h.MSG_ELEMENT_TYPE.IMAGE:
        i += u(t);
        break;

      case h.MSG_ELEMENT_TYPE.SOUND:
        i += s(t);
        break;

      case h.MSG_ELEMENT_TYPE.FILE:
        i += g(t);
        break;

      case h.MSG_ELEMENT_TYPE.LOCATION:
        break;

      case h.MSG_ELEMENT_TYPE.CUSTOM:
        i += f(t);
        break;

      case h.MSG_ELEMENT_TYPE.GROUP_TIP:
        i += T(t);
        break;

      default:
        h.Log.error("未知消息元素类型: elemType=" + n);
    }
    return h.Tool.formatHtml2Text(i);
}

function a(o) {
    return o.getText();
}

function c(o) {
    return o.getData();
}

function u(o) {
    var e = o.getImage(h.IMAGE_TYPE.SMALL), r = o.getImage(h.IMAGE_TYPE.LARGE), n = o.getImage(h.IMAGE_TYPE.ORIGIN);
    return r || (r = e), n || (n = e), "<img src='" + e.getUrl() + "#" + r.getUrl() + "#" + n.getUrl() + "' style='CURSOR: hand' id='" + o.getImageId() + "' bigImgUrl='" + r.getUrl() + "' onclick='imageClick(this)' />";
}

function s(o) {
    o.getSecond();
    var e = o.getDownUrl();
    return "ie" == h.BROWSER_INFO.type && parseInt(h.BROWSER_INFO.ver) <= 8 ? "[这是一条语音消息]demo暂不支持ie8(含)以下浏览器播放语音,语音URL:" + e : '<audio src="' + e + '" controls="controls" onplay="onChangePlayAudio(this)" preload="none"></audio>';
}

function g(o) {
    var e = Math.round(o.getSize() / 1024);
    return '<a href="' + o.getDownUrl() + '" title="点击下载文件" ><i class="glyphicon glyphicon-file">&nbsp;' + o.getName() + "(" + e + "KB)</i></a>";
}

function f(o) {
    return "data=" + o.getData() + ", desc=" + o.getDesc() + ", ext=" + o.getExt();
}

function T(o) {
    var e, r, n, t, i = "";
    switch (e = o.getOpType(), r = o.getOpUserId(), e) {
      case h.GROUP_TIP_TYPE.JOIN:
        n = o.getUserIdList();
        for (var a in n) if (i += n[a] + ",", n.length > 10 && 9 == a) {
            i += "等" + n.length + "人";
            break;
        }
        i = i.substring(0, i.length - 1), i += "进入房间", t = parseInt(t) + 1;
        break;

      case h.GROUP_TIP_TYPE.QUIT:
        i += r + "离开房间", t > 0 && (t = parseInt(t) - 1);
        break;

      case h.GROUP_TIP_TYPE.KICK:
        i += r + "将", n = o.getUserIdList();
        for (var a in n) if (i += n[a] + ",", n.length > 10 && 9 == a) {
            i += "等" + n.length + "人";
            break;
        }
        i += "踢出该群";
        break;

      case h.GROUP_TIP_TYPE.SET_ADMIN:
        i += r + "将", n = o.getUserIdList();
        for (var a in n) if (i += n[a] + ",", n.length > 10 && 9 == a) {
            i += "等" + n.length + "人";
            break;
        }
        i += "设为管理员";
        break;

      case h.GROUP_TIP_TYPE.CANCEL_ADMIN:
        i += r + "取消", n = o.getUserIdList();
        for (var a in n) if (i += n[a] + ",", n.length > 10 && 9 == a) {
            i += "等" + n.length + "人";
            break;
        }
        i += "的管理员资格";
        break;

      case h.GROUP_TIP_TYPE.MODIFY_GROUP_INFO:
        i += r + "修改了群资料：";
        var c, u, s = o.getGroupInfoList();
        for (var a in s) switch (c = s[a].getType(), u = s[a].getValue(), c) {
          case h.GROUP_TIP_MODIFY_GROUP_INFO_TYPE.FACE_URL:
            i += "群头像为" + u + "; ";
            break;

          case h.GROUP_TIP_MODIFY_GROUP_INFO_TYPE.NAME:
            i += "群名称为" + u + "; ";
            break;

          case h.GROUP_TIP_MODIFY_GROUP_INFO_TYPE.OWNER:
            i += "群主为" + u + "; ";
            break;

          case h.GROUP_TIP_MODIFY_GROUP_INFO_TYPE.NOTIFICATION:
            i += "群公告为" + u + "; ";
            break;

          case h.GROUP_TIP_MODIFY_GROUP_INFO_TYPE.INTRODUCTION:
            i += "群简介为" + u + "; ";
            break;

          default:
            i += "未知信息为:type=" + c + ",value=" + u + "; ";
        }
        break;

      case h.GROUP_TIP_TYPE.MODIFY_MEMBER_INFO:
        i += r + "修改了群成员资料:";
        var g, f, T = o.getMemberInfoList();
        for (var a in T) if (g = T[a].getUserId(), f = T[a].getShutupTime(), i += g + ": ", 
        i += null != f && void 0 !== f ? 0 == f ? "取消禁言; " : "禁言" + f + "秒; " : " shutupTime为空", 
        T.length > 10 && 9 == a) {
            i += "等" + T.length + "人";
            break;
        }
        break;

      default:
        i += "未知群提示消息类型：type=" + e;
    }
    return i;
}

function p() {
    console.warn("tlslogin need rewrite");
}

function l(o) {
    var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, r = arguments[2];
    if (O.identifier) if (R) {
        var n = o, i = h.Tool.getStrBytes(o);
        if (n.length < 1) console.error("发送的消息不能为空!"); else {
            var a, c;
            if (v == h.SESSION_TYPE.GROUP ? (a = h.MSG_MAX_LENGTH.GROUP, c = "消息长度超出限制(最多" + Math.round(a / 3) + "汉字)") : (a = h.MSG_MAX_LENGTH.C2C, 
            c = "消息长度超出限制(最多" + Math.round(a / 3) + "汉字)"), i > a) console.error(c); else {
                L || (L = new h.Session(v, R, R, U, Math.round(new Date().getTime() / 1e3)));
                var u, s = Math.round(4294967296 * Math.random()), g = Math.round(new Date().getTime() / 1e3);
                u = v == h.SESSION_TYPE.GROUP ? h.GROUP_MSG_SUB_TYPE.COMMON : h.C2C_MSG_SUB_TYPE.COMMON;
                var o = new h.Msg(L, !0, -1, s, g, O.identifier, u, O.identifierNick), f = /\[[^[\]]{1,3}\]/gm, T = (n.match(f), 
                O.identifierNick), l = O.avatar;
                /进入房间/gi.test(n) && (T = "系统消息");
                var _ = {
                    ispic: e,
                    live_id: O.live_id,
                    nickname: T,
                    avatar: l
                }, d = new h.Msg.Elem.Custom(n, "", JSON.stringify(_));
                o.addCustom(d), h.sendMsg(o, function(e) {
                    v == h.SESSION_TYPE.C2C && t(o), h.Log.info("发消息成功"), r && r();
                }, function(o) {
                    h.Log.error("发消息失败:" + o.ErrorInfo), console.error("发消息失败:" + o.ErrorInfo);
                });
            }
        }
    } else console.error("您还没有进入房间，暂不能聊天"); else 1 == N ? (h.Tool.setCookie("accountType", O.accountType, 86400), 
    p()) : console.error("请填写帐号和票据");
}

function _() {}

function d() {}

function E() {}

function I() {}

function G() {}

function m(o) {
    $("#send_msg_text").val($("#send_msg_text").val() + o.id);
}

function M(o, e, r, n, t, i) {
    var a = "收到一条群系统消息: type=" + o + ", typeCh=" + e + ",群ID=" + r + ", 群名称=" + n + ", 内容=" + t + ", 时间=" + h.Tool.formatTimeStamp(i);
    h.Log.warn(a), console.error(a);
}

var O, N, P, S, y, v, R, L, U, h = require("./webim.js");

module.exports = {
    init: function(o) {
        N = o.accountMode, P = o.accountType, S = o.sdkAppID, y = o.avChatRoomId, v = o.selType, 
        R = o.selToID;
    },
    onBigGroupMsgNotify: function(o, e) {
        for (var r = o.length - 1; r >= 0; r--) {
            var n = o[r];
            h.Log.warn("receive a new avchatroom group msg: " + n.getFromAccountNick()), e(t(n));
        }
    },
    onMsgNotify: function(e) {
        for (var r in e) o(e[r]);
    },
    handlderMsg: o,
    sdkLogin: e,
    applyJoinBigGroup: n,
    showMsg: t,
    convertMsgtoHtml: i,
    convertTextMsgToHtml: a,
    convertFaceMsgToHtml: c,
    convertImageMsgToHtml: u,
    convertSoundMsgToHtml: s,
    convertFileMsgToHtml: g,
    convertLocationMsgToHtml: function(o) {
        return "经度=" + o.getLongitude() + ",纬度=" + o.getLatitude() + ",描述=" + o.getDesc();
    },
    convertCustomMsgToHtml: f,
    convertGroupTipMsgToHtml: T,
    tlsLogin: p,
    tlsGetUserSig: function(o) {
        if (o.ErrorCode == h.TLS_ERROR_CODE.OK) {
            O.identifier = h.Tool.getQueryString("identifier"), O.userSig = o.UserSig, O.sdkAppID = O.appIDAt3rd = Number(h.Tool.getQueryString("sdkappid"));
            var r = h.Tool.getCookie("accountType");
            r ? (O.accountType = r, e()) : location.href = location.href.replace(/\?.*$/gi, "");
        } else o.ErrorCode == h.TLS_ERROR_CODE.SIGNATURE_EXPIRATION ? p() : console.error("[" + o.ErrorCode + "]" + o.ErrorInfo);
    },
    imageClick: function(o) {
        var e = o.src.split("#"), r = e[0], n = e[1], t = e[2];
        h.Log.info("小图url:" + r), h.Log.info("大图url:" + n), h.Log.info("原图url:" + t);
    },
    onChangePlayAudio: function(o) {
        curPlayAudio ? curPlayAudio != o && (curPlayAudio.currentTime = 0, curPlayAudio.pause(), 
        curPlayAudio = o) : curPlayAudio = o;
    },
    smsPicClick: function() {
        O.identifier ? (d(), _()) : 1 == N ? (h.Tool.setCookie("accountType", O.accountType, 86400), 
        p()) : console.error("请填写帐号和票据");
    },
    onSendMsg: l,
    sendGroupLoveMsg: function() {
        if (O.identifier) if (R) {
            L || (L = new h.Session(v, R, R, U, Math.round(new Date().getTime() / 1e3)));
            var o = Math.round(4294967296 * Math.random()), e = Math.round(new Date().getTime() / 1e3), r = h.GROUP_MSG_SUB_TYPE.LOVEMSG, n = new h.Msg(L, !0, -1, o, e, O.identifier, r, O.identifierNick), i = new h.Msg.Elem.Text("love_msg");
            n.addText(i), h.sendMsg(n, function(o) {
                v == h.SESSION_TYPE.C2C && t(n), h.Log.info("点赞成功");
            }, function(o) {
                h.Log.error("发送点赞消息失败:" + o.ErrorInfo), console.error("发送点赞消息失败:" + o.ErrorInfo);
            });
        } else console.error("您还没有进入房间，暂不能点赞"); else 1 == N ? (h.Tool.setCookie("accountType", O.accountType, 86400), 
        p()) : console.error("请填写帐号和票据");
    },
    hideDiscussForm: function() {},
    showDiscussForm: _,
    hideDiscussTool: d,
    showDiscussTool: function() {},
    hideDiscussEmotion: E,
    showDiscussEmotion: I,
    showLoveMsgAnimation: G,
    initEmotionUL: function() {
        return;
    },
    showEmotionDialog: function() {
        openEmotionFlag ? (openEmotionFlag = !1, E()) : (openEmotionFlag = !0, I());
    },
    selectEmotionImg: m,
    quitBigGroup: function() {
        var o = {
            GroupId: y
        };
        h.quitBigGroup(o, function(o) {
            h.Log.info("退群成功"), L = null;
        }, function(o) {
            console.error(o.ErrorInfo);
        });
    },
    logout: function() {
        h.logout(function(o) {
            h.Log.info("登出成功"), O.identifier = null, O.userSig = null;
        });
    },
    onApplyJoinGroupRequestNotify: function(o) {
        h.Log.warn("执行 加群申请 回调：" + JSON.stringify(o));
        var e = o.MsgTime, r = o.Operator_Account + "申请加入你的群";
        M(o.ReportType, "[申请加群]", o.GroupId, o.GroupName, r, e);
    },
    onApplyJoinGroupAcceptNotify: function(o) {
        h.Log.warn("执行 申请加群被同意 回调：" + JSON.stringify(o));
        var e = o.Operator_Account + "同意你的加群申请，附言：" + o.RemarkInfo;
        M(o.ReportType, "[申请加群被同意]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onApplyJoinGroupRefuseNotify: function(o) {
        h.Log.warn("执行 申请加群被拒绝 回调：" + JSON.stringify(o));
        var e = o.Operator_Account + "拒绝了你的加群申请，附言：" + o.RemarkInfo;
        M(o.ReportType, "[申请加群被拒绝]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onKickedGroupNotify: function(o) {
        h.Log.warn("执行 被踢出群  回调：" + JSON.stringify(o));
        var e = "你被管理员" + o.Operator_Account + "踢出该群";
        M(o.ReportType, "[被踢出群]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onDestoryGroupNotify: function(o) {
        h.Log.warn("执行 解散群 回调：" + JSON.stringify(o));
        var e = "群主" + o.Operator_Account + "已解散该群";
        M(o.ReportType, "[群被解散]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onCreateGroupNotify: function(o) {
        h.Log.warn("执行 创建群 回调：" + JSON.stringify(o));
        M(o.ReportType, "[创建群]", o.GroupId, o.GroupName, "你创建了该群", o.MsgTime);
    },
    onInvitedJoinGroupNotify: function(o) {
        h.Log.warn("执行 被邀请加群  回调: " + JSON.stringify(o));
        var e = "你被管理员" + o.Operator_Account + "邀请加入该群";
        M(o.ReportType, "[被邀请加群]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onQuitGroupNotify: function(o) {
        h.Log.warn("执行 主动退群  回调： " + JSON.stringify(o));
        M(o.ReportType, "[主动退群]", o.GroupId, o.GroupName, "你退出了该群", o.MsgTime);
    },
    onSetedGroupAdminNotify: function(o) {
        h.Log.warn("执行 被设置为管理员  回调：" + JSON.stringify(o));
        var e = "你被群主" + o.Operator_Account + "设置为管理员";
        M(o.ReportType, "[被设置为管理员]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onCanceledGroupAdminNotify: function(o) {
        h.Log.warn("执行 被取消管理员 回调：" + JSON.stringify(o));
        var e = "你被群主" + o.Operator_Account + "取消了管理员资格";
        M(o.ReportType, "[被取消管理员]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onRevokeGroupNotify: function(o) {
        h.Log.warn("执行 群被回收 回调：" + JSON.stringify(o));
        M(o.ReportType, "[群被回收]", o.GroupId, o.GroupName, "该群已被回收", o.MsgTime);
    },
    onCustomGroupNotify: function(o) {
        h.Log.warn("执行 用户自定义系统消息 回调：" + JSON.stringify(o));
        var e = o.UserDefinedField;
        M(o.ReportType, "[用户自定义系统消息]", o.GroupId, o.GroupName, e, o.MsgTime);
    },
    onGroupInfoChangeNotify: function(o) {
        h.Log.warn("执行 群资料变化 回调： " + JSON.stringify(o));
        var e = o.GroupId, r = (o.GroupFaceUrl, o.GroupName);
        o.OwnerAccount, o.GroupNotification, o.GroupIntroduction;
        r && h.Log.warn("群id=" + e + "的新名称为：" + r);
    },
    showGroupSystemMsg: M
};